package com.web.portal.service;

import java.util.EnumMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.web.portal.dao.BaseDao;
import com.web.portal.dao.LabSearchType;
import com.web.portal.entity.Lab;

@Service (value="labService")
public class DefaultLabService extends DefaultWebPortalService<Lab> implements LabService {
	private static final Logger LOG=Logger.getLogger(DefaultLabService.class);

	public void addOrEditLabInfo(Lab labinfo) {
		createOrUpdate(labinfo);
		
	}

	public Lab getLab(int id) {
		// TODO Auto-generated method stub
		return null;
	}
	@Autowired
	@Qualifier (value="labDao")
	public void init(BaseDao dao){
		setBaseDao(dao);
	}
	

	@Override
	@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
	protected boolean isCreate(Lab entity) throws RuntimeException {
		// TODO Auto-generated method stub
		return false;
	}

	public Lab getLab(String id) {
		Map<LabSearchType,Object> labSearchCriteria= new EnumMap(LabSearchType.class);
		labSearchCriteria.put(LabSearchType.ID, id);
		List<Lab> labList= searchByCriteria(labSearchCriteria);
		if(!labList.isEmpty() && labList.size()==1){
			LOG.debug("Lab info found for given " +id +"......................................");
			return labList.get(0);
			
		}
		LOG.debug("Multiple records found for given id................");
		return null;
	}

	public List<Lab> getLab(Lab lab) {
		// TODO Auto-generated method stub
	return getList(lab);
	}

}
